<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 和相同的二元子数组 -->
    <script>
      var numSubarraysWithSum = function (nums, goal) {
        let sum = 0
        const sumcount = new Map()
        let count = 0
        for (const num of nums) {
          sumcount.set(sum, (sumcount.get(sum) || 0) + 1)
          sum += num
          count += sumcount.get(sum - goal) || 0
        }
        return count
      }
      // console.log(numSubarraysWithSum([1, 0, 1, 0, 1], (goal = 2)))
      console.log(numSubarraysWithSum((nums = [0, 0, 0, 0, 0]), (goal = 0)))
    </script>
  </body>
</html>
